<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
if(!isset($_SESSION['user'])){
	echo "timeout";
}else{
include '../operations/connection.php';	
include 'substring-comment.php';
$id = $_REQUEST['idproject'];
$id_employee = $_SESSION['IDEmployee'];

$lang=$_SESSION['lang'];
		
		if ($lang == "EN") {
			include "../value/value_en.php";
		} else if($lang== "VN") {
			include "../value/value_vn.php";
		}
		else {
			include "../value/value_kr.php";
		}

$page = isset ( $_REQUEST["page"] ) ? intval ( $_REQUEST["page"] ) : 1;

$rows_per_page = 20;

$page_start = ( $page - 1 ) * $rows_per_page;
$page_end = $page * $rows_per_page; 


$_SESSION['searchProject']="";
$_SESSION['datefromproject']=date("Y-m-d");
$_SESSION['datetoproject']=date("Y-m-d");
$_SESSION['IDSearchproject']="";
$_SESSION['textSearchproject']="";
$_SESSION['EmployeeSearchproject']=0;
$_SESSION['typeSearchproject']=0;
$_SESSION['typeSearch1project']=0;


$s = (string)(microtime(true)*1000);
$queryListErrorByIDPr = mysql_query("SELECT tp.IDTest, tp.Title, tp.TextTest, tp.Time, tp.`Status`, tp.`Correct`,e.FullName,
				tp.IDTestTemp,pp.IDView,pp.NameProject,pc.backgroundColor,pc.backgroundConfirm,tp.Comment_Last,tp.NameEmployee_Last 
			   FROM pr_testproject tp, employee e ,pr_project pp,priority_color pc  WHERE pp.IDProject = tp.IDProject AND tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			    AND pc.id = tp.IdPriorityColor ".$_SESSION['searchProject']." ORDER BY tp.`Status`=2 ASC,tp.DateConfirm DESC,tp.IdPriorityColor DESC,tp.Time DESC; ");


//$s1 = (string)(microtime(true)*1000);
//$s2=$s1-$s;
//echo $s1.'-'.$s.'='.$s2;

$number_of_page = ceil ( mysql_num_rows( $queryListErrorByIDPr ) / $rows_per_page );

$_SESSION['projects'] = 'include-list-error-pro.php' ;

$queryLstMember=mysql_query("SELECT c.IDComposition, c.IDEmployee, c.IDProject, c.Position, c.Status, e.UserName, e.FullName,
        		 e.Position as PositionEmp,e.Email,c.REmail FROM pr_composition c, employee e 
        		 WHERE c.IDProject = '$id' AND c.IDEmployee = e.IDEmployee and c.Status=0 and e.State = 1 ");



$datefrom=date("Y-m-d");
$dateto=date("Y-m-d");
	$row_array = array();
	$index = 0;
	$mangtester='';
	while ($row = mysql_fetch_array($queryLstMember)){
			$row_array[$index][0] = $row['IDEmployee'];
			$row_array[$index][1] = $row['Position'];
			$row_array[$index][2] = $row['FullName'];
			$row_array[$index][3] = $row['Status'];
			if($row[Position]==0 && $row['REmail']==1){
				if($mangtester==''){
					$mangtester=$row['IDEmployee'];
				}else{
					$mangtester .=",".$row['IDEmployee'];
				}
			}
			$index += 1;
		}
		$_SESSION['mangtestererror']=$mangtester;
?>




       


<a class="caption"><?php echo $l_list_error?> </a>
		<div class="divError divinvi" >
			<div class="rf-p divListError">
				<ul>
					<li><a  class="linkAction" href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=1">
						<img src="images/list.png" alt="" />
						<span
							style="display: inline-block; width: 100%"><?php echo $l_error?>
						</span> </a></li>
					<li style="left: 150px"><a  class="linkAction" href="project.php?projectDetail=project_feature&id=<?=$id?>&tab=2"><img
							src="images/recyclebin_empty.png" alt="" /><span
							style="display: inline-block; width: 100%"><?php echo $l_newfewture;?>
						</span> </a>
					</li>
					<?php if (($_SESSION['poscoder']==1)|| ($_SESSION['posmanager']==1)){ ?>
						<li style="left: 150px">
						<a  class="linkAction" onclick="if(confirm('Do you want notice new version to testers?')){ sendEmailNewVersion('<?=$_SESSION['mangtestererror']?>','<?=$_SESSION['namepro_temp']?>'); return true;}else{return false;}">
							<img src="images/newversion.png" alt="" />
							<span style="display: inline-block; width: 100%"><?php echo $l_newversion;?>
							</span> 
						</a>
					</li>
					<?php }?>	
				</ul>
			</div>
			
			<table  border="1" bordercolor="#C5D1E8" cellpadding="4"  style="border-collapse:collapse;width: 100%">
												<tr height="40">
												<td align="center" style="vertical-align:middle;width: 120px"><?=$l_created_date?></td>
												<td style="height:24px;padding-left: 3px">
												<input type="text" id="datefrom" name="datefrom" value="<?=$_SESSION['datefromproject']?>" class="ftext" readonly="readonly" style="font-size:12px;font-weight:bold;text-align:center;"/>
												~
												<input type="text" id="dateto" name="dateto" value="<?=$_SESSION['datetoproject']?>" class="ftext" readonly="readonly" style="font-size:12px;font-weight:bold;text-align:center;"/>				
												</td>
																				
												</tr>
												
												<tr height="40">
												<td align="center" style="vertical-align:middle">ID</td>
												<td style="padding-left: 3px;padding-right: 3px;">
													<input type="text" id="IDSearch" name="IDSearch" value="<?=$_SESSION['IDSearchproject']?>" style="width:50px;height:20px;" />
												</td>
												</tr>
												<tr height="40">
												<td align="center" style="vertical-align:middle">Text</td>
												<td style="padding-left: 3px;padding-right: 3px;">
													<input type="text" id="textSearch" name="textSearch" value="<?=$_SESSION['textSearchproject']?>" style="width:300px;height:20px;" />
													<label><input type="radio" value="0" name="typeSearch1" id="title1"  <?php if($_SESSION['typeSearch1project']==0){?>checked="checked"<?php }?>/>Title</label>
													<label><input type="radio" value="1" name="typeSearch1" id="content1" <?php if($_SESSION['typeSearch1project']==1){?>checked="checked"<?php }?>/>Content</label>
												</td>
												
												</tr>
												<tr height="40">
												<td align="center" style="vertical-align:middle"><?=$l_employee?></td>
												<td style="padding-left: 3px;padding-right: 3px;">
													<select id='EmployeeSearch' name="EmployeeSearch" style="height: 24px">
														<option value="0"><?php echo $l_all;?></option>
														<?php foreach ($row_array as $row){
															if(($row[0]==$_SESSION['IDEmployee']) && ($row[1]==0)){
																$_SESSION['postest']=1;
															}
															if($row[1]==0){?>
															<option value="<?php echo $row[0];?>" <?php if($row[0]==$_SESSION['EmployeeSearchproject']){?> selected="selected"<?php }?>><?php echo $row[2];?></option>
														<?php }} ?>
													</select>
												</td>
												</tr>
												<tr height="40">
												<td align="center" style="vertical-align:middle"><?=$l_type_project?></td>
												<td style="padding-left: 3px;padding-right: 3px;">
													<select id='typeSearch' name="typeSearch" style="height: 24px">
														<option value="0" <?php if($_SESSION['typeSearchproject']==0){?>selected="selected"<?php }?>><?php echo $l_all;?></option>
														<option value="1" <?php if($_SESSION['typeSearchproject']==1){?>selected="selected"<?php }?>><?php echo $l_newerror;?></option>
														<option value="2" <?php if($_SESSION['typeSearchproject']==2){?>selected="selected"<?php }?>><?php echo $l_incorrect;?></option>
														<option value="3" <?php if($_SESSION['typeSearchproject']==3){?>selected="selected"<?php }?>><?php echo $l_no_fix;?></option>
														<option value="4" <?php if($_SESSION['typeSearchproject']==4){?>selected="selected"<?php }?>><?php echo $l_fix_complete;?></option>
														<option value="5" <?php if($_SESSION['typeSearchproject']==5){?>selected="selected"<?php }?>><?php echo $l_confirm_excel;?></option>
													</select>
												</td>
												</tr>
												
												<tr>
												<td align="center" style="vertical-align:middle"><?=$l_charger?></td>
												<td style="padding-left: 3px;padding-right: 3px;">
													<select id='chargerSearch' name="chargerSearch" style="height: 24px">
														<option value="0"><?php echo $l_all;?></option>
														<?php foreach ($row_array as $row){
															
															if($row[1]==1){?>
															<option value="<?php echo $row[0];?>" <?php if($row[0]==$_SESSION['chargerSearchproject']){?> selected="selected"<?php }?>><?php echo $row[2];?></option>
														<?php }} ?>
													</select>
												</td>
												</tr>
												<tr>
												<td colspan="2" style="height: 40px;padding-left: 30px;">
												<input  type="button" onclick="searchProject(0,<?=$id?>)" value="<?= $l_search ?>" class="btnupbg btnupload" style="background: #4f81bd;width: 80px" />
												<input onclick="searchProject(1,<?=$id?>)" id="1" type="button" value="<?=$l_yesterday?>" class="btnupbg btnupload" style="background: #4f81bd;width: 80px" />
                								<input onclick="searchProject(7,<?=$id?>)" id="7" type="button" value="<?= $oneweek ?>" class="btnupbg btnupload" style="background: #4f81bd;width: 80px" />
                								<input onclick="searchProject(30,<?=$id?>)"id="30" type="button" value="<?= $one_month ?>" class="btnupbg btnupload" style="background: #4f81bd;width: 80px" />
												<input  type="button" onclick="allProject(<?=$id?>)" value="<?= $l_all?>" class="btnupbg btnupload" style="background: #4f81bd;width: 80px" />
												</td>	</tr>
											</table>	
			<table width="100%" class="rf-dt" >
				<tr style="background-color: #EEE" >
					<td class="rf-dt-c"	style="width:7%;vertical-align: middle; text-align: center;min-width: 7%;font-size: 13px;font-weight: bold;"><?=$l_code?></td>
					<td class="rf-dt-c"	style="width:5%;vertical-align: middle; text-align: center;min-width: 5%;font-size: 13px;font-weight: bold;">
						<?=$l_state?>
					</td>
					<td class="rf-dt-c" style="padding: 7px; vertical-align: middle; width: 55%;font-size: 13px;font-weight: bold;">
						<?=$l_title?>
					</td>
					<td class="rf-dt-c"	style="vertical-align: middle; text-align: center; width: 9%;font-size: 13px;font-weight: bold;">
						<?=$l_writer?>
					</td>
					<td class="rf-dt-c"	style="vertical-align: middle; text-align: center; width: 80px;font-size: 13px;font-weight: bold;">
						<?=$l_created_date?>
					</td>
					<td class="rf-dt-c"	style="vertical-align: middle; text-align: center; width: 9%;font-size: 13px;font-weight: bold;">
						<?php echo $l_charger;?>
					</td>
					<td class="rf-dt-c"	style="vertical-align: middle; text-align: center; width: 80px;font-size: 13px;font-weight: bold;">
						<?php echo $l_deadline?>
					</td>
					<td class="rf-dt-c"	style="vertical-align: middle; text-align: center; width: 50px;font-size: 13px;font-weight: bold;">
						<?php echo $l_reopen;?>
					</td>

				</tr>
				</table>

											
			<div id='ajaxdelete'>
				<table width="100%" class="rf-dt" id="report">
			<?php 
			if(mysql_num_rows($queryListErrorByIDPr)>0){
			$i = 0;
			while ($row=mysql_fetch_array($queryListErrorByIDPr)){
				if ( $i >= $page_start ){
				$idtestproject = $row['IDTest'];
				$titletestpro = $row['Title'];
				$contenttestpro = $row['TextTest'];
				$fullnames = $row['FullName'];
				$time = $row['Time'];
				$deadline = $row['DeadLine'];
				$c_reopen = $row['c_reopen'];
				$indexcomment = (($page-1)*20)+$i;
				
				$stringcolortest = substr($row['Title'],0,-14);
				$stringcolor = substr($row['Comment_Last'],0,-14);
				
				
				//tag html tranh be giao dien
				$stringcolor = strip_tags($stringcolor);
				
				$idtesppr_temp = $row['IDTestTemp'];
				$idviewpro = $row['IDView'];
				$nampro = $row['NameProject'];
				
				$temp_mo = explode("-", $idtesppr_temp);
				$temp_mo_last = $temp_mo[0];
				$m="";
				if ($temp_mo_last==''){
					$m ="";
				}
				else if ($temp_mo_last==$nampro){
					$m = $idviewpro."-".$temp_mo[1];
				}else{
					$m = $idviewpro."-".$idtesppr_temp;
				}
				
				$bgcolor = $row['backgroundColor'];
				
				$correct=$row['Correct'];
				
				$status = $row['Status'];
				$temp_status ="";
				if ($status==2){
					$bgcolor = $row['backgroundConfirm'];
					if($correct==0)
						$bgcolor = "B0A5CA";
				}
				if($row['Delete']==1)
					$bgcolor='8A898F';
				?>
				<tr style="background: <?php echo "#".$bgcolor;?>" >
					<td class="rf-dt-c"
						style="width:7%;vertical-align: middle; text-align: center;min-width: 7%"><?=$m;?></td>
					<td class="rf-dt-c"
						style="width:5%;vertical-align: middle; text-align: center;min-width: 5%">
						<?php if ($row['Delete']==1){?><span title="<?=$l_deleted?>" class="clickedit" style="width:60px;">
							<img src="images/del.png"  style="width: 32px;" alt="<?php echo $l_deleted?>" /></span>
						<?php }else if ($status==0){?><span title="<?=$l_no_fix?>" class="clickedit" style="width:60px;">
							<img src="images/unconfirm.png"  style="width: 32px;" alt="<?php echo $l_no_fix?>" /></span>
						<?php }else if ($status==1){?>
							<span title="<?=$l_fix_complete?>" class="clickedit" style="width:60px;">
							<img src="images/fixed.png"  style="width: 32px;" alt="<?php echo $l_fix_complete?>" /></span>
						<?php }else if ($status==2){?>
							<span title="<?=$l_confirm_excel?>" class="clickedit" style="width:60px;">
							<img src="images/confirm.png"  style="width: 32px;" alt="<?php echo $l_confirm_excel?>" /></span>
						<?php }else if ($status==-1){
								if($correct==1){
								?>
								<span title="<?=$l_newerror?>" class="clickedit" style="width:60px;">
								<img src="images/newerror.png"  style="width: 32px;" alt="<?php echo $l_newerror?>" /></span>
							<?php }else{?>
								<span title="<?php echo $l_incorrect;?>" class="clickedit" style="width:60px;">
								<img src="images/notfix.png"  style="width: 32px;" alt="<?php echo $l_incorrect;?>" />
								</span>
						<?php }}?>
					</td>
					<td class="rf-dt-c" 
						style="padding: 7px; vertical-align: middle; width: 55%;">
						<div class="rowMinHeight" align="left" style="width: 98%;">
							<span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" onclick="showcommanderror('<?=$m?>','<?=$idtestproject?>','<?=$id_employee?>','<?=$id?>',0, this,'<?=$page?>');" class="titleError">
								 <a class="bclick" style="color: #424242;cursor:pointer;padding:2px;">
									<?php if(strlen($stringcolortest)==0){ echo  $titletestpro ;}else{echo  $stringcolortest;}?>
									<?php $querytranslate = mysql_query("select c.IDComment,c.IDTestProject,c.IDEmployee,c.Comment,c.DateComment,
								 e.IDEmployee,e.FullName,c.IDTestProject from pr_translate c, employee e 
									 where c.IDEmployee = e.IDEmployee and c.IDTestProject = '$idtestproject' ORDER BY  c.DateComment ASC;");

	                        if(mysql_num_rows($querytranslate)>0){
						                        echo '<br>';
						                        
						                        while ($rowcoment = mysql_fetch_array($querytranslate)){
						                        		$idcomment = $rowcoment['IDComment'];
						                        		$idemployeecomment = $rowcoment['IDEmployee'];
														$stringcolor1 = substr($rowcoment['Comment'],0,-14);
														?>
												<div style="padding-top:5px;font-size: 13px;background: <?php echo "#".$bgcolor;?>;color: #424242;border-bottom: 1px solid #C4C0C9;border-right: 1px solid #C4C0C9;"  >
							                        	<span style="font-size: 13px; color: #424242;"> <?php if (strlen($stringcolor1)==0){echo " $l_translate : ".$rowcoment['Comment'];}else{echo "$l_translate : ".$stringcolor1;}?>
							</span> <i style="color:#424242; display:block; text-align:right;padding-right:15px; font-size: 13px;"><?php echo $rowcoment['FullName']." (".$rowcoment['DateComment'].")"?></i>
						                         </div>
					                  	 <?php }
	                         } 
	                         $querycause = mysql_query("select c.IDComment,c.IDTestProject,c.IDEmployee,c.Comment,c.DateComment,
								 e.IDEmployee,e.FullName,c.IDTestProject from pr_cause c, employee e 
									 where c.IDEmployee = e.IDEmployee and c.IDTestProject = '$idtestproject' ORDER BY  c.DateComment ASC;");
	                         if(mysql_num_rows($querycause)>0){
	                        	 echo '<br>';

	                         	while ($rowcoment = mysql_fetch_array($querycause)){
						                        		$idcomment = $rowcoment['IDComment'];
						                        		$idemployeecomment = $rowcoment['IDEmployee'];
														$stringcolor1 = substr($rowcoment['Comment'],0,-14);
														?>
												<div style="padding-top:5px;font-size: 13px;background: <?php echo "#".$bgcolor;?>;color: #424242;border-bottom: 1px solid #C4C0C9;border-right: 1px solid #C4C0C9;"  >
							                        	<span style="font-size: 13px; color: #424242;"> <?php if (strlen($stringcolor1)==0){echo " $l_cause : ".$rowcoment['Comment'];}else{echo "$l_cause : ".$stringcolor1;}?>
							</span> <i style="color:#424242; display:block; text-align:right;padding-right:15px; font-size: 13px;"><?php echo $rowcoment['FullName']." (".$rowcoment['DateComment'].")"?></i>
						                         </div>
					                  	 <?php }
	                         }?> 
								</a> 
							</span>
							<div class="writeBy">
							
								<div align="right" style="width: 99%; float: left;">
								<span><?php include_once 'substring-comment.php';?>
								<?php 
								if (strlen($stringcolor)==0){echo substringProvider::catchuoi($row['Comment_Last'],27);}else{
									echo substringProvider::catchuoi($stringcolor,27);}
								?>
								</span>
								<span style="font-weight: bold;"><?php  if ($row['NameEmployee_Last']!="") {
										echo '('.$row['NameEmployee_Last'].')';
									}?>
								</span>	
								</div>
							</div>
						</div>
					</td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 9%;">
						<?php echo $fullnames?></td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 80px;"><?php echo $time?>
					</td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 9%;">
						<?php
						$sqlcharge=mysql_query("SELECT e.FullName,SUM(c.`status`) as charge from pr_charge c,employee e 
								WHERE c.id_testproject='$idtestproject' AND c.id_employee=e.IDEmployee GROUP BY c.id_employee;");
						while ($r=mysql_fetch_array($sqlcharge)){
							if($r['charge']==1){
								echo $r['FullName'].'<br>';
							}
						}
						
						?></td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 80px;"><?php echo $deadline?>
					</td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 50px;"><?php echo $c_reopen?>
				</tr>
				<tr style="background: #f2f9ff; display:none" id="commentprojecthide" >
				</tr>
				<?php
						}
							$i++;
							if ($i >= $page_end){
								break;
							}
							}
						}
						?>
						<tr>
							<td class="rf-dt-ftr-c" style="text-align: center; " colspan="8">
									<span style="padding:1px; display: inline-block;">
										<?php if ( $number_of_page > 1 ) 
										{ 
											if ($page==1)
												$p=2;
											else if ($page==$number_of_page)
												$p=$number_of_page-1;
											else $p=$page;
											if($page!=1){?>
												<a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=1&page=<?=1?>">
					 								<span class="button_next" style="border:none"><?php echo "<<<<"?></span></a> 
					 							<a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=1&page=<?=($page-1)?>">
					 								<span onmouseover="" class="button_next" style="border:none"><?php echo "<<"?></span></a>
											<?php  }
											else{
												echo "<span class='button_next' style='cursor:default'><<<</span>"; 
												echo "<span class='button_next' style='cursor:default'><<</span>";
											}
											for ( $i = $p-1; $i <= $p+1; $i++ ) {	
													if ($i<=$number_of_page && $i>0)
														if ($i==$page){
															echo "<span class='button_next' style='color: blue;'><b>".$i."</b></span>"; 
														}else{
														?>
															<a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=1&page=<?=$i?>">
				     	 									<span class="button_next" style="border:none;color: #508e21;" ><b><?php echo $i;?></b></span></a>
															<?php 
														}
													?>
											<?php 
													}
												if($page!=$number_of_page){ ?>
													<a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=1&page=<?=($page+1)?>">
					 									<span class="button_next" style="border:none"><?php echo ">>"?> </span></a>
					 								<a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=1&page=<?=$number_of_page?>">
					 									<span class="button_next" style="border:none"><?php echo ">>>"?> </span></a>
												<?php }
												else{
													echo "<span class='button_next' style='cursor:default'>>></span> ";
													echo "<span class='button_next' style='cursor:default'>>>></span> ";
												}
											}
											
											?>
									</span>
		               			 </td>
							</tr>
			</table>

			</div>
			</div>
<?php

//$s1 = (string)(microtime(true)*1000);
//$s2=$s1-$s;
//echo $s1.'-'.$s.'='.$s2;
mysql_close($connection);
}?>